﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPF各种控件样式
{
    /// <summary>
    /// 委托事件
    /// </summary>
    public partial class DeleGateEventWin : Window
    {

        public DeleGateEventWin()
        {
            InitializeComponent();
            btn_OK.Click += new RoutedEventHandler(btn_OK_Click);

        }
        public void Run()
        {
            MessageBox.Show("事件触发！");
        }
        void btn_OK_Click(object sender, RoutedEventArgs e)
        {
            EventRun eventrun = new EventRun();
            eventrun.eventRun += new EventRun.DelegateRun(eventrun_eventRun);
            eventrun.Begin();
        }

        void eventrun_eventRun(object sender)
        {
            Run();
        }

    }

    public class EventRun
    {
        public delegate void DelegateRun(object sender);//定义委托
        public event DelegateRun eventRun;//定义事件 
        public object sender { get; set; }
        public void Begin()
        {
            eventRun(sender);
        }
    }
}
